package com.example.smartcity_poverty.ui.AllService.TrafficViolationsInquiry

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import com.example.smartcity_poverty.App.Companion.getToken
import com.example.smartcity_poverty.R
import com.example.smartcity_poverty.logic.Repository.api
import com.example.smartcity_poverty.logic.Repository.coroutine
import com.example.smartcity_poverty.logic.util.Util.show
import kotlinx.android.synthetic.main.activity_tvi.*
import kotlinx.coroutines.Dispatchers

/**
 * 违章查询功能模块
 */
class TviActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        setContentView(R.layout.activity_tvi)
        title = "违章查询"

        tvHomeOk.setOnClickListener {
            if (tvHomeEditText1.text.isNotEmpty() || tvHomeEditText2.text.isNotEmpty()) {
                if (getToken().isNotEmpty()) {

                    // 开启协程
                    coroutine(Dispatchers.IO) {
                        val rl = api.getTvHomeList(getToken(), "京A123")
                        runOnUiThread {
                            rl.msg?.show()
                            "${rl.rows?.size}".show()
                        }
                    }
                } else "请先登录！".show()

            } else "不能为空！".show()
        }

    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        finish()
        return super.onOptionsItemSelected(item)
    }
}